package com.it.park.controller.user;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.it.park.client.service.IntegralConsumeService;
import com.it.park.client.service.IntegralIncomeService;
import com.it.park.common.Page;
import com.it.park.constant.Constant;
import com.it.park.model.IntegralConsume;
import com.it.park.model.IntegralIncome;
import com.it.park.rms.client.model.User;

/**
 * @author Administrator
 *积分管理
 */
@Controller
@RequestMapping("/user/integral")
public class IntegralController {
	private String rootPath=Constant.USER_PATH;
	private Page page;
	@Autowired
	private IntegralConsumeService consumeService;
	@Autowired
	private IntegralIncomeService incomeService;
	/**
	 *积分管理页面
	 */
	@RequestMapping("integralManage")
	public String integralManage(){
		return rootPath+"integral/integralManage";
	}
	
	/**
	 * 消费记录
	 * @param pageNow
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("consumeRecord")
	public String consumeRecord(Integer pageNow,HttpServletRequest request,HttpSession session){
		Map<String,Object> map = new HashMap<String, Object>();
		User user = (User) session.getAttribute("user");
		map.put("userId", user.getId());
		Integer total = consumeService.selectTotal(map);
		page = new Page(pageNow,total,10);
		map.put("startPos", page.getStartPos());
		map.put("pageSize", page.getPageSize());
		List<IntegralConsume> integralConsumes  = consumeService.selectPagination(map);
		request.setAttribute("total", total);
		request.setAttribute("page", page);
		request.setAttribute("integralConsumes", integralConsumes);
		return rootPath+"integral/integralRecord";
	}
	
	/**
	 * 消费站内收入
	 * @param pageNow
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("integralIncome")
	public String integralIncome(Integer pageNow,HttpServletRequest request,HttpSession session){
		Map<String,Object> map = new HashMap<String, Object>();
		User user = (User) session.getAttribute("user");
		map.put("userId", user.getId());
		Integer total = incomeService.selectTotal(map);
		page = new Page(pageNow,total,10);
		map.put("startPos", page.getStartPos());
		map.put("pageSize", page.getPageSize());
		List<IntegralIncome> integralIncomes  = incomeService.selectPagination(map);
		request.setAttribute("total", total);
		request.setAttribute("page", page);
		request.setAttribute("integralIncomes", integralIncomes);
		return rootPath+"integral/integralIncome";
	}
	
	
}
